#include <stdio.h>
#include <pthread.h>

#include "xmlrpc/server.h"
#include "dmx/dmx.h"

int mode = 0;	/*stores the mode of the moodlight env. 0 = fixed color, 1 = slow changing, etc -> wiki */

void init_xmlrpc()
{
    printf("XMLRPC:	Starting XML-RPC server...\n");
    init_xmlrpc_server();
}

void * init_dmx()
{
    printf("DMX:	Sending DMX...\n");
    transmit_dmx();
}

int main(void){
    printf("Main:	OpenMood\n");
//    printf("Main:	Version: SVN %s\n", SVN_REV);
    
    /*Threads init*/
    pthread_t xmlrpc_server, dmx_transmitter;
    int iret1, iret2;
    
    /* Create independent threads each of which will execute function */
    
    iret1 = pthread_create( &xmlrpc_server, NULL, init_xmlrpc, NULL);
    iret2 = pthread_create( &dmx_transmitter, NULL, init_dmx, NULL);
    
    if (iret1){
	printf("Main:		ERROR; return code from pthread_create() is %d\n", iret1);
	exit(-1);
    }

    if (iret2){
	printf("Main:		ERROR; return code from pthread_create() is %d\n", iret2);
	exit(-1);
    }
    
    /* Wait till threads are complete before main continues. Unless we */
    /* wait we run the risk of executing an exit which will terminate  */
    /* the process and all threads before the threads have completed.  */
    
    pthread_join( xmlrpc_server, NULL);
    pthread_join( dmx_transmitter, NULL);
    
    printf("Main:	Thread 1 returns: %d\n", iret1);
    printf("Main:	Thread 2 returns: %d\n", iret2);
    
    return 0;
}